<template>
  <div id="app">
    <h2>测试题</h2>
    <SubjectItemVue :list="list" ref="sub" @sum="sum"></SubjectItemVue>
    <div>
      <FlagItemVue :list="list"></FlagItemVue>
    </div>
  </div>
</template>

<script>
import FlagItemVue from './components/FlagItem.vue'
import SubjectItemVue from './components/SubjectItem.vue'
export default {
  components: {
    FlagItemVue,
    SubjectItemVue
  },
  data () {
    return {
      list: [
        {
          num1: Math.floor(Math.random() * 10),
          num2: Math.floor(Math.random() * 10),
          status: '未完成',
          result: '',
          submitted: false
        },
        {
          num1: Math.floor(Math.random() * 10),
          num2: Math.floor(Math.random() * 10),
          status: '未完成',
          result: '',
          submitted: false
        },
        {
          num1: Math.floor(Math.random() * 10),
          num2: Math.floor(Math.random() * 10),
          status: '未完成',
          result: '',
          submitted: false
        },
        {
          num1: Math.floor(Math.random() * 10),
          num2: Math.floor(Math.random() * 10),
          status: '未完成',
          result: '',
          submitted: false
        }
      ]
    }
  },
  methods: {
    sum (id) {
      // this.list[id].result = val
      // console.log(val)
      if (this.list[id].result === '') {
        return (this.list[id].status = '未完成')
      }
      if (this.list[id].num1 + this.list[id].num2 === +this.list[id].result) {
        return (this.list[id].status = '回答正确')
      }
      if (this.list[id].num1 + this.list[id].num2 !== +this.list[id].result) {
        return (this.list[id].status = '回答错误')
      }
    }
  }
}
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>
